<template>
	<view>
		<view class="content">
			<view v-if="list.length>0">
				<view class="list" v-for="(item,index) in list" :key="index">
					<view class="title">
						<view class="icon"></view>
						确认时间:
						<view class="date"><text>30 </text> 分钟</view>
					</view>
					<view class="up">
						<view class="left">
							<view class="number">
								{{item.apply_price}} <text>Fmb</text>
							</view>
							<view class="text">
								兑换数量
							</view>
						</view>
						<view class="right">
							<view class="view">
								<view class="name">
									兑换目标
								</view>
								<view class="text">
									{{item.buy_username}}
								</view>
							</view>
							<view class="view">
								<view class="name">
									兑换时间
								</view>
								<view class="date">
									{{item.cj_time}}
								</view>
							</view>
						</view>
					</view>
					<view class="down">
						<u-button class="b1" @click="checkSafePasswordEmpty(index,1)"  shape="circle">
							<image src="../static/w1.png" mode=""></image>同意
						</u-button>
						<u-button class="b2" @click="checkSafePasswordEmpty(index,2)" shape="circle">
							<image src="../static/w2.png" mode=""></image>驳回
						</u-button>
					</view>
				</view>
			</view>
			<view class="none" v-else>
				<view class="none-view">
					<image src="../../../static/image/none.png" class="none-image"></image>
					<view class="none-name">
						暂无相关数据~
					</view>
				</view>
			</view>
		</view>
		<u-keyboard mode="number" :dot-enabled="false" v-model="pay" :tooltip="false" @change="onChange" @backspace="onBackspace">
			<view>
				<view class="u-text-center">
					<view class="u-text-name">
						二级密码
					</view>
					<view class="u-text-text">
						您当前正在进行交易，为确保账户安全请输入二级 密码验证身份
					</view>
				</view>
				<view class="u-flex u-row-center">
					<u-message-input mode="box" :maxlength="6" :dot-fill="true" v-model="password" :disabled-keyboard="true"></u-message-input>
				</view>
				<view class="u-text-center u-padding-top-10 u-padding-bottom-20 tips"></view>
			</view>
		</u-keyboard>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				list: [],
				page: 1,
				pay: false,
				password: "",
				index: 0,
				type: 0
			}
		},
		onLoad(option) {
			than = this;
			than.post("api/kmb/lookMessage", {
				type: 'guomi_count'
			}, function(data) {})
		},
		onShow() {
			than.listOfWaitVerify()
		},
		onReachBottom() {
			than.page++;
			than.listOfWaitVerify()
		},
		methods: {
			onChange(val) {
				if (this.password.length < 6) {
					this.password += val;
				}

				if (this.password.length >= 6) {

					if (than.type == 1) {
						than.agreeApplySell()
					} else {
						than.refuseApplySell()
					}
				}
			},
			onBackspace(e) {
				if (this.password.length > 0) {
					this.password = this.password.substring(0, this.password.length - 1);
				}
			},
			checkSafePasswordEmpty(index, type) {
				than.index = index
				than.type = type
				than.post("api/member/checkSafePasswordEmpty", null, function(data) {
					if (parseInt(data) == 0) {
						than.toast("未设置二级密码")
						uni.navigateTo({
							url: "/pages/htmlA/setting/twopassword"
						})
					} else {
						than.pay = true;
					}
				})
			},
			agreeApplySell(index) {
				than.post("api/kmb_apply/agreeApplySell", {
					zhujian_id: than.list[than.index].zhujian_id,
					password: than.password
				}, function(data) {
					than.pay = false;
					than.toast(data)
					than.list.splice(than.index, 1);
				})
			},
			refuseApplySell(index) {
				than.post("api/kmb_apply/refuseApplySell", {
					zhujian_id: than.list[than.index].zhujian_id,
					password: than.password
				}, function(data) {
					than.pay = false;
					than.toast(data)
					than.list.splice(than.index, 1);
				})
			},
			listOfWaitVerify() {
				than.post("api/kmb/applyList", {
					page: than.page,
					apply_type: 3
				}, function(data) {
					if (than.page == 1) {
						than.list = data;
					} else {
						than.list = than.list.concat(data)
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background: #F4F4F7;
	}

	.content {
		padding: 20rpx 36rpx;

		.list {
			height: 367rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin-bottom: 20rpx;

			.title {
				display: flex;
				align-items: center;
				height: 84rpx;

				.icon {
					width: 12rpx;
					height: 12rpx;
					background: #2FD09E;
					border-radius: 50%;
					margin-left: 27rpx;
					margin-right: 7rpx;
				}

				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #4A5062;

				.date {
					margin-left: 9rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #205FFA;

					text {
						font-size: 36rpx;
						font-family: Myriad Pro;
						font-weight: 400;
						color: #205FFA;
						margin-right: 5rpx;
					}
				}
			}

			.up {
				display: flex;
				align-items: center;
				padding: 0 24rpx;

				.left {
					width: 201rpx;
					height: 163rpx;
					margin-right: 25rpx;
					text-align: center;
					background: #FDF4ED;
					border-radius: 10rpx;

					.number {
						margin-top: 22rpx;
						font-size: 44rpx;
						font-family: Myriad Pro;
						font-weight: bold;
						color: #F66337;

						text {
							font-size: 28rpx;
							margin-left: 5rpx;
						}
					}

					.text {
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #1B1B1B;
					}
				}

				.right {
					width: 403rpx;
					height: 163rpx;
					background: #F7F8FD;
					border-radius: 10rpx;

					.view {
						margin-top: 20rpx;
						display: flex;
						align-items: center;
					}

					.name {
						margin: 0 17rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #4A5062;
					}

					.text {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #999999;
					}

					.date {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
					}
				}
			}

			.down {
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.b1 {
					image {
						width: 36rpx;
						height: 36rpx;
						margin-right: 15rpx;
					}

					margin-right: 0;
					padding: 0;
					width: 147rpx;
					height: 60rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}

				.b2 {
					margin-right: 25rpx;
					margin-left: 25rpx;
					width: 147rpx;
					height: 60rpx;
					padding: 0;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-right: 15rpx;
					}

					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
			}
		}
	}
</style>
